import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { Router } from '@angular/router';
import { masterService } from '../lib/master.service';
import { saveVarService } from '../lib/saveVar.service';
import { ToasterService } from 'angular2-toaster';

@Component({
    selector: 'cms-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
    providers: [masterService]
})

export class AppComponent implements OnInit {
    constructor(public _masterService: masterService,
        public _saveVarService: saveVarService,
        private _router: Router,
        public _changeDetectorRef: ChangeDetectorRef,
        public toasterService: ToasterService
    ) {
        this.toasterService = toasterService;
    }

    ngOnInit() { }

    logOff() {
        localStorage.clear();
        this._router.navigate(['/login'])
    }

    popToast(toasterConfigs: any) {
        this.toasterService.pop(toasterConfigs.type, toasterConfigs.title, toasterConfigs.body);
    }

    toastSuccess(msg: string, timeout?) {
        let toast = {
            type: 'success',
            body: msg,
            showCloseButton: true,
            timeout: timeout ? timeout : 5000
        }
        this.toasterService.pop(toast);
    }

    toastError(msg: string, timeout?) {
        let toast = {
            type: 'error',
            body: msg,
            showCloseButton: true,
            timeout: timeout ? timeout : 5000
        }
        this.toasterService.pop(toast);
    }

    toastWarning(msg: string) {
        let toast = {
            type: 'warning',
            body: msg,
            showCloseButton: true
        }
        this.toasterService.pop(toast);
    }
}
